define(function(require, exports, module) {
	var $ = require('$'),
      _ = require('underscore'),
      Backbone = require('backbone'),
      Datepicker = require('datepicker');

	module.exports = Backbone.View.extend({
		el: '.popup-meeting',
		events: {
			'click .button-submit': 'onSubmit'
		},
		template: require('tpl/plan/form.handlebars'),
		initialize: function(options) {
			var self = this;
			this.gomac = options.gomac;
			//初始化视图
			this.$el.html(this.template( this.model.toForm() ));
			//获取表单元素
			this.form = this.$el.find('.meeting-form');
			//表单初始化
			this.gomac.formFromJSON(this.form, this.model.toForm());
			//日期控件初始化
			Datepicker({});

			this.$el.on('closed', function(e) { self.undelegateEvents(); });
		},
		onSubmit: function(e) {
			var self = this;
		  //获取表单数据
      var data = self.gomac.formToJSON(self.form);
      //更新模型
      var rtn = self.model.fromForm(data);
      if(rtn.code===0) {
          //设置成功，保存
          self.model.save(null, {
          	success: function(model, resp, options) {
          		//保存成功
          		//关闭弹窗
          		self.gomac.closeModal(self.$el);
              var MeetingApp = require('app/plan');
              //添加到视图中
              (new MeetingApp({gomac: self.gomac})).prependOne(model);
              //切换标签
              self.gomac.showTab('#coming');
          	},
          	error: function(model, resp, options) {
          		self.gomac.alert('保存安排时出错');
              console.log('保存安排时出错', model, resp, options);
          	}
          });
      } else {
          self.gomac.alert(rtn.message);
          console.log('表单数据有误', rtn);
      }
		}
	});
});